﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = null;
}
<link href="~/lib/layui/css/layui.css" rel="stylesheet" />
<script src="~/lib/layui/layui.js"></script>
<script src="~/js/js.cookie.js"></script>
<script src="~/js/moment.js"></script>
<script src="~/lib/jquery/dist/jquery.js"></script>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 请勿在项目正式环境中引用该 layui.css 地址 -->
    <link href="//unpkg.com/layui@2.9.18/dist/css/layui.css" rel="stylesheet">
   @*  <!-- 引入Layui的CSS -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/layui-v2.7.2/dist/css/layui.css">
    <!-- 引入qrcode.js库 -->
    <script src="https://cdn.jsdelivr.net/npm/qrcodejs2@1.0.0/qrcode.min.js"></script> *@
</head>
<body>
    <h3>
        <i class="layui-icon layui-icon-left" style="color: #dcccc0"></i><a style="color: #dcccc0;cursor:pointer" onclick="location.href='/MaterialManagements/MaterialManagementsSearch'"> 返回&nbsp;&nbsp;</a><span style="color: #000">|</span>&nbsp;&nbsp;物料编辑&nbsp;<span style="color: #000">(<span class="layui-icon layui-icon-backspace"></span>)</span>
    </h3>
    <form class="layui-form" action="">

        <div class="layui-inline">
            <label class="layui-form-label">物料/服务</label>
            <div class="layui-input-inline">
                <select name="materialsServicesId" id="materialsServicesId" lay-verify="required" lay-search>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">物料编码</label>
            <div class="layui-input-block">
                <input type="text" name="materialCode" id="materialCode" lay-verify="required" placeholder="请输入物料编码" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">物料名称</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="materialName" id="materialName" lay-verify="required" autocomplete="off" lay-reqtext="请输入物料名称" lay-affix="clear" class="layui-input demo-phone">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">物料类别</label>
            <div class="layui-input-inline">
                <select name="materialCategoryId" id="materialCategoryId" lay-verify="required" lay-search>
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">物料单位</label>
            <div class="layui-input-inline">
                <select name="materialUnitId" id="materialUnitId" lay-verify="required" lay-search>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">规格</label>
            <div class="layui-input-block">
                <input type="text" name="specifications" id="specifications" lay-verify="required" placeholder="请输入规格" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">规格单位</label>
            <div class="layui-input-inline">
                <select name="specificationUnitId" id="specificationUnitId" lay-verify="required" lay-search>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">包装规格</label>
            <div class="layui-input-block">
                <input type="text" name="packagingSpecifications" id="packagingSpecifications" lay-verify="required" placeholder="请输入包装规格" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">启动质检管理</label>
            <div class="layui-input-inline">
                <select name="isInspection" id="isInspection" lay-verify="required" lay-search>
                    <option value="">请选择</option>
                    <option value="1">是</option>
                    <option value="2">否</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">库存上限</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="inventoryLimit" id="inventoryLimit" autocomplete="off" lay-reqtext="请输入库存上限" lay-affix="clear" class="layui-input demo-phone">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">库存下限</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="inventoryLowerLimit" id="inventoryLowerLimit" autocomplete="off" lay-reqtext="请输入库存下限" lay-affix="clear" class="layui-input demo-phone">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">存货科目</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="inventoryAccount" id="inventoryAccount" autocomplete="off" lay-reqtext="请输入销售收入科目" lay-affix="clear" class="layui-input demo-phone">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">销售收入科目</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="salesRevenueAccount" id="salesRevenueAccount" autocomplete="off" lay-reqtext="请输入销售收入科目" lay-affix="clear" class="layui-input demo-phone">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">销售成本科目</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="salesCostAccount" id="salesCostAccount" autocomplete="off" lay-reqtext="请输入销售成本科目" lay-affix="clear" class="layui-input demo-phone">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">物料二维码</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" name="materialQRCode" id="materialQRCode" autocomplete="off" lay-reqtext="请输入物料二维码" lay-affix="clear" class="layui-input demo-phone">
            </div>
        </div>

        @*  <div class="layui-container">
                <div class="layui-row">
                    <div class="layui-col-xs12 layui-col-md6 layui-col-md-offset3">
                        <h2 class="layui-text-center">根据名称生成QRCode</h2>
                        <div class="layui-form-item">
                            <label class="layui-form-label">名称</label>
                            <div class="layui-input-block">
                                <input type="text" id="nameInput" placeholder="请输入名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="button" class="layui-btn" id="generateBtn">生成QRCode</button>
                            </div>
                        </div>
                        <div class="layui-form-item" style="margin-top: 20px;">
                            <div class="layui-input-block">
                                <div id="qrcode"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div> *@

        <div class="layui-inline">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <select name="isStatus" id="isStatus" lay-verify="required" lay-search>
                    <option value="">请选择</option>
                    <option value="1">有效</option>
                    <option value="2">无效</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" id="component" class="layui-btn layui-btn-normal" lay-submit lay-filter="demo-val">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
   @*  <!-- 引入Layui的JS -->
    <script src="https://cdn.jsdelivr.net/npm/layui-v2.7.2/dist/layui.js"></script> *@
    <script>
        layui.use(['form', 'laydate', 'util'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;
            var util = layui.util;
            searchMaterialsServices()//物料/服务
            searcMaterialCategory()//物料类别
            searchMaterialUnit()//物料单位
            searchSpecificationUnit()//规格单位

            // // 监听生成QRCode按钮点击事件
            // document.getElementById('generateBtn').addEventListener('click', function(){
            //     var name = document.getElementById('nameInput').value;
            //         if(name){
            //             // 生成QRCode 
            //             new QRCode(document.getElementById('qrcode'), {
            //                 text: name,
            //                 width: 200,
            //                 height: 200
            //             });
            //         } 
            //         else
            //         {
            //             layui.layer.msg('请输入名称！');
            //         }
            // });
            //物料管理添加
              // 表单取值
            layui.$('#component').on('click', function () {
                var data = form.val('demo-val-filter');
            });

            // 添加提交事件
            form.on('submit(demo-val)', function (data) {
                var field = data.field; // 获取表单字段值
                var username=localStorage.getItem('userName');
                console.log(username);
                field.createdOwner = username;
                field.createdTime = "" || new Date().toISOString();
                field.updateOwner = "" || null;
                field.updateTime = "" || new Date().toISOString();
                field.examineOwner = "" || null;
                field.examineTime = "" || new Date().toISOString();
                field.auditStatus = 1;
                field.isDel = 1;
                console.log(field) //在控制台显示值
                // 此处可执行 Ajax 等操作
                $.ajax({
                    type: "post",
                    url: '@ViewBag.RedDragonWrite'+"/api/MaterialManagements/CreateMaterialManagement",
                    data: JSON.stringify(field),
                    dataType: "json",
                    contentType: "application/json",
                    success: res => {
                        console.log(res)
                        // 处理响应，例如提示成功信息
                        layui.layer.msg(res.msg ,{ icon: 6, time: 1000 });
                    },
                    error: function (xhr, status, error) {
                        // 处理错误
                        layui.layer.msg('添加失败', { icon: 5, time: 1000 });
                    }
                })
                return false; // 阻止默认 form 跳转
            });
             //物料/服务下拉框绑定
            function searchMaterialsServices() {
                $.ajax({
                    url: '@ViewBag.RedDragonWrite'+'/api/MaterialManagements/SearchMaterialsServices',
                    type: 'get',
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.materialsServicesId + '">' + item.materialsServicesName + '</option>';
                        });
                        $('#materialsServicesId').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                })
            }
             //物料类别下拉框绑定
            function searcMaterialCategory() {
                $.ajax({
                    url:  '@ViewBag.RedDragonWrite'+'/api/MaterialManagements/SearcMaterialCategory',
                    type: 'get',
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.materialCategoryId + '">' + item.materialCategoryName + '</option>';
                        });
                        $('#materialCategoryId').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                })
            }
             //物料单位下拉框绑定
            function searchMaterialUnit() {
                $.ajax({
                    url:  '@ViewBag.RedDragonWrite'+'/api/MaterialManagements/SearchMaterialUnit',
                    type: 'get',
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.materialUnitId + '">' + item.materialUnitName + '</option>';
                        });
                        $('#materialUnitId').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                })
            }
             //规格单位下拉框绑定
            function searchSpecificationUnit() {
                $.ajax({
                    url: '@ViewBag.RedDragonWrite'+ '/api/MaterialManagements/SearchSpecificationUnit',
                    type: 'get',
                    dataType: 'json',
                    success: res => {
                        console.log(res)
                        var options = '<option value="0">请选择</option>';
                        $.each(res.data, function (index, item) {
                            options += '<option value="' + item.specificationUnitId + '">' + item.specificationUnitName + '</option>';
                        });
                        $('#specificationUnitId').html(options);
                        form.render('select'); // 更新下拉框渲染
                    }
                })
            }


        })
    </script>
</body>

</html>